package com.copa.controller;

import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesis;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisParam;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import dev.langchain4j.community.model.dashscope.WanxImageModel;
import dev.langchain4j.data.image.Image;
import dev.langchain4j.model.output.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author copa
 * @date 2025/8/17 00:04
 * @description:
 */
@RestController
@Slf4j
public class WanxImageModelController {

    @Autowired
    private WanxImageModel wanxImageModel;

    @GetMapping(value = "/image/create2")
    public String createImageContent2() {
        System.out.println(wanxImageModel);
        Response<Image> imageResponse = wanxImageModel.generate("可爱哒皮丘");
        System.out.println(imageResponse.content().url());
        return imageResponse.content().url().toString();
    }

    @GetMapping(value = "/image/create3")
    public String createImageContent3() {
        String prompt = "一只可爱的皮丘~头上带着2025的帽子~水印写着：b站copaa";
        ImageSynthesisParam param = ImageSynthesisParam.builder()
                        .apiKey(System.getenv("aliQwen-api"))
                        .model(ImageSynthesis.Models.WANX_V1)
                        .prompt(prompt)
                        .style("<watercolor>")
                        .n(1)
                        .size("1024*1024")
                        .build();
        ImageSynthesis imageSynthesis = new ImageSynthesis();
        ImageSynthesisResult result = null;
        try {
            System.out.println("---sync call, please wait a moment----");
            result = imageSynthesis.call(param);
        } catch (ApiException | NoApiKeyException e){
            throw new RuntimeException(e.getMessage());
        }
        System.out.println(JsonUtils.toJson(result));
        return JsonUtils.toJson(result);
    }
}
